package com.chinasofti.zbest.service.impl;

import com.chinasofti.zbest.dao.model.Category;
import com.chinasofti.zbest.dao.model.Product;
import com.chinasofti.zbest.dao.ProductMapper;
import com.chinasofti.zbest.service.IProductService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.chinasofti.zbest.service.info.CategoryInfo;
import com.chinasofti.zbest.service.info.ProductInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;

/**
 * <p>
 * 商品 服务实现类
 * </p>
 *
 * @author zbest
 * @since 2019-05-28
 */
@Service("productService")
@Slf4j
public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> implements IProductService {

    @Autowired
    private ProductMapper productMapper;

    /**
     * 按销量排序
     * @param count
     * @return
     */
    @Override
    public List<Product> findSell(int count) {
        List<Product> topProducts=productMapper.selectTop(count);
        return topProducts;
    }

    /**
     * 搜索
     * @param productName 搜索名
     * @return
     */
    @Override
    public List<Product> search(String productName) {

        List<Product> productList=productMapper.search(productName);
        return productList;
    }

    @Override
    public List<Product> searchIdea(int categoryId) {
        List<Product> searIdea=productMapper.searchIdea(categoryId);
        return searIdea;
    }

    /**
     * 根据商品编号显示
     * @param counts
     * @return
     */
    @Override
    public List<ProductInfo> searchProduct(int counts) {
        List<ProductInfo> searchList=productMapper.searchProduct(counts);
        return searchList;
    }

    /**
     * 根据类型名显示商品
     * @param counts
     * @return
     */
    @Override
    public List<ProductInfo> searchName(int counts) {
        List<ProductInfo> searchList=productMapper.searchName(counts);
        return searchList;
    }

    /**
     * 上架日期方法
     * @param count
     * @return
     */
    @Override
    public List<ProductInfo> searchDate(int count) {
        List<ProductInfo> searchDay=productMapper.searchDate(count);
        return searchDay;
    }

    /**
     * 根据分类id显示商品
     * @param categoryId
     * @return
     */
    @Override
    public List<ProductInfo> searchCategoryId(int categoryId) {
        log.info("x"+categoryId);
        List<ProductInfo> searchCatId=productMapper.searchCategoryId(categoryId);
        return searchCatId;
    }

    @Override
    public List<Product> search(String inputInfo,String sortBy) {
        log.info("service中的："+inputInfo);
        log.info("service中的："+sortBy);
        List<Product> result=null;
        switch (sortBy){
            case "新品上市":
                log.info("按新品上市搜索");
                result = productMapper.searchByDate(inputInfo);
                break;
            case "销量从高到低":
                result = productMapper.searchBySalesH(inputInfo);
                break;
            case "销量从低到高":
                result = productMapper.searchBySalesL(inputInfo);
                break;
            case "价格从高到低":
                result = productMapper.searchByPriceH(inputInfo);
                break;
            case "价格从低到高":
                result = productMapper.searchByPriceL(inputInfo);
                break;
            default:
                result = productMapper.searchBy(inputInfo);
        }
        return result ;
    }

    @Override
    public List<String> orderByCategoryName() {
        return productMapper.orderByCategoryName();
    }

    @Override
    public List<String> orderByDriedFlowerType() {
        return productMapper.orderByDriedFlowerType();
    }

    @Override
    public List<String> orderByPutPosition() {
        return productMapper.orderByPutPosition();
    }

    @Override
    public List<String> orderByFit() {
        return productMapper.orderByFit();
    }

    @Override
    public List<String> orderByColor() {
        return productMapper.orderByColor();
    }

    @Override
    public void midifyProCount(Integer productId,Integer proCount,Integer proSales) {
        productMapper.midifyProCount(productId,proCount,proSales);
    }

    @Override
    public Product queryByProductNum(String productNumber) {
        Product product = productMapper.queryByProductNum(productNumber);
        return product;
    }
}
